package com.data;

import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

public class EntryPoint {

    private static final Logger log = Logger.getLogger(EntryPoint.class);

    public static void main(String[] args) {

        if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
            System.out.println("You can invoke following commands:");
            System.out.println("1. start (this command starts <<Transfer Data>> task).");
            System.out.println("2. list (this command lists all data from db_tables)");
            System.out.println("3. insert, with arg[1]='table name', arg[2]='table primary key' (this command inserts new table to be read)");
            System.out.println("4. activate, with arg[1]='true/false', arg[2]='table name' (this command activates/deactivates specified table)");
            return;
        }

        if (args[0].equalsIgnoreCase("start")) {
            SpringApplication.run(ApplicationConfiguration.class);
            //SpringApplication.run(new Object[] {TransferDataTask.class, ApplicationConfiguration.class}, new String[]{});
        } else if (args[0].equals("list")) {
            DaoUtils.newInstance().listTableRows();
        } else if (args.length == 3 && !args[1].isEmpty() && !args[2].isEmpty()) {
            if (args[0].equalsIgnoreCase("insert")) {
                DaoUtils.newInstance().addNewScanTable(args[1], args[2]);
            } else if (args[0].equalsIgnoreCase("activate")) {
                DaoUtils.newInstance().activateScanRow(Boolean.valueOf(args[1]), args[2]);
            } else {
                System.out.println("Unknown command");
            }
        } else {
            System.out.println("Unknown command");
        }
    }
}
